﻿using System;
using System.Collections.Generic;

using Microsoft.Xna.Framework;

using FarseerPhysics.Factories;
using FarseerPhysics.Dynamics;

using ZoeEngine.Components.Physics;

namespace ZoeEngine.Framework.Collision
{
    public class PhysCircle : PhysShape
    {
        private float _radius;
        private Vector2 _offset;

        public PhysCircle(float radius, float density = 10.0f, Vector2 offset = default(Vector2))
        {
            this._radius = Utility.ToMeters(radius);
            this._density = Utility.ToMeters(density);
            this._offset = Utility.ToMeters(offset);
        }
        public override void AttachShape(PhysBodyComponent parent)
        {
            this._parent = parent;
            Fixture f = FixtureFactory.AttachCircle(_radius, _density, _parent.Body, _offset, _parent);
            f.Friction = _friction;
            f.Restitution = _restitution;
        }

        public float Radius
        {
            get
            {
                return Utility.ToPixels(_radius);
            }
            set
            {
                _radius = Utility.ToMeters(value);
                if (_parent != null)
                {
                    _parent.BuildCollisionShapes();
                }
            }
        }
    }
}
